{extend name="layouts/main" /}
{block name="link"}{/block}
{block name="css"}
<style>
	.layui-form-item {
		margin-bottom: -8px;
	}
	.layui-form-item .layui-input-inline {
		width: 120px;
	    margin-right: 19px;
	}
</style>
{/block}
{block name="content"}
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
	<div class="layui-body layui-tab-content site-demo site-demo-body" style="top: 0px;left: 0px;">
		<div class="layui-tab-item layui-show">
			<div class="layui-main">
				<div id="LAY_preview">
					<div class="layui-fluid" style="position: relative;margin: 0 auto;padding: 0 0px;">
						<div class="layui-set">
							<div class="layui-set-from search-form">
								<form class="layui-form" action="">
									<div class="layui-form-item">
										<div class="layui-input-inline" style="width:80px;float: left;">
											<?php if($category_id):?>
												<a class="layui-btn" href="javascript:;" onclick="x_admin_show('新增','{:url('add',['category_id'=>$category_id,'model_id'=>$model_id])}','100%','100%',1)" title="新增">新增文档</a>
											<?php else:?>
											<!-- <button class="layui-btn" id="search">新增文档</button> -->
											<ul class="layui-nav" style="width: 100px;height: 40px;padding: 0px 0px 0px 0px;background-color: #009688;">
												<!-- 栏目列表 -->
												<li class="layui-nav-item" style="line-height: 46px;">
													<a href="javascript:;" style="padding-left: 15px;">新增文档</a>
													<dl class="layui-nav-child" style="top:42px;width:200px;height: 400px; overflow:scroll">
														{volist name=":get_list_cate()" id="addcategory"}
														<dd>
															<a href="javascript:;" onclick="x_admin_show('新增','{:url('add',array('category_id'=>$addcategory['id'],'model_id'=>$addcategory['model_id']))}','100%','100%',1)">
																{php} echo str_repeat('&nbsp;&nbsp;',  $addcategory['level']- 1);if($addcategory['level'] >1)echo ' ├─ ';  {/php}
																{$addcategory.typename}
															</a>
														</dd>
														{/volist}
													</dl>
												</li>
											</ul>
											<?php endif;?>
										</div>
										<div style="float: right;">
											<!-- <input type="hidden" name="page" value="{:input('page')}"> -->
											<input type="hidden" name="category_id" value="{:input('category_id')}">
											<div class="layui-input-inline" style="width: 180px;margin-right: 5px;">
												<input type="text" name="date" value="{:input('date')}" class="layui-input" id="laydate" placeholder="搜索时间范围">
											</div>
											<div class="layui-input-inline" style="width: 100px;margin-right: 5px;">
												<select name="status" id="status" lay-verify="required">
													<option value="" selected="selected">选择状态</option>
													<option value="1">显示</option>
													<option value="0">隐藏</option>
													<option value="2">待审核</option>
													<option value="3">草稿</option>
													<option value="-1">已删除</option>
												</select>
											</div>
											<div class="layui-input-inline" style="width: 120px;margin-right: 5px;">
												<select name="sort" id="sort" lay-verify="required">
													<option value="" selected="selected">排序</option>
													<option value="update_time-up">更新时间-升</option>
													<option value="update_time-down">更新时间-降</option>
													<option value="view-up">浏览率-升</option>
													<option value="view-down">浏览率-降</option>
													<option value="sort-up">排序号-升</option>
													<option value="sort-down">排序号-降</option>
													<option value="id-up">ID号-升</option>
													<option value="id-down">ID号-降</option>
												</select>
											</div>
											<div class="layui-input-inline" style="width: 100px;margin-right: 5px;">
												<select name="flags" lay-verify="required">
													<option value="" selected="selected">属性</option>
													{volist name=":get_field_attr()" id="vo"}
													<option value="{$key}">{$key}:{$vo}</option>
													{/volist}
												</select>
											</div>
											<div class="layui-input-inline" style="margin-right: 5px;width: 150px;">
												<input type="text" name="title" value="{:input('title')}"  placeholder="搜索关键词" autocomplete="off" class="layui-input search-input">
											</div>
											<div class="layui-input-inline" style="width:39px">
												<button class="layui-btn" id="search" style="height: 36px;"><i class="layui-icon"></i></button>
											</div>
										</div>
									</div>
								</form>
							</div>
						</div>
						<div class="layui-card" style="overflow-y: hidden;float: left;width: 100%;">
							<form class="layui-form" action="">
								<table class="layui-table" lay-filter="tableEvent">
									<colgroup>
										<col width="1">
										<col width="5%">
										<col width="7%">
										<col>
										<col width="23%">
										<col width="13%">
										<col width="10%">
										<col width="18%">
									</colgroup>
									<thead>
										<tr>
											<th style="text-align: center;"><input type="checkbox" lay-skin="primary" id="allChoose" lay-filter="allChoose"></th>
											<th style="text-align: center;">ID</th>
											<th style="text-align: center;">序号</th>
											<th style="text-align: center;">标题</th>
											<th style="text-align: center;">分类</th>
											<th style="text-align: center;">更新时间</th>
											<th style="text-align: center;">状态</th>
											<th style="text-align: center;">操作</th>
										</tr>
									</thead>
									<tbody>
										{volist name="list" id="info"}
										<tr>
											<td>
												<input type="checkbox" lay-skin="primary" class="ids" name="ids[{$info.id}-{$info.model_id}]" value="{$info.id}" id-cid="{$info.id}-{$info.category_id}" lay-filter="c_one">
											</td>
											<td>{$info.id}</td>
											<td><input type="text" name="sort[{$info.id}-{$info.model_id}]" value="{$info.sort}" class="layui-input sort" lay-filter="weight"></td>
											<td title="{$info.title}">{$info.title|cut_str=###,8} <br>
											{if condition="$info['flags']"}
											[<?php echo $info['flags_str'];?>]
											{/if}
											</td>
											<td align="center">
												{:get_category_title($info.category_id)}
												[
												{$info.category_id}
												=
												{:get_category_byid($info.category_id,'name')}
												]<br>
												<a class="layui-btn layui-btn-xs" href="{:url('document')}?category_id={$info.category_id}">
													内容
												</a>
												<a class="layui-btn layui-btn-xs" href="javascript:;" onclick="x_admin_show('{:get_category_title($info.category_id)}','{:url('cms.Arctype/edit',array('id'=>$info['category_id']))}','60%','100%',0)">
													查看
												</a>
											</td>
											<td>
												{$info.update_time|date="Y-m-d"}
												<br>&nbsp;
												{$info.update_time|date="H:i:s"}
											</td>
											<td>
												<!--{$info.status_text}-->
												<input type="checkbox" class="switch" {if condition="$info['status'] eq 1"} checked="" {/if} url="{:url('set_status')}" on="ids={$info.id}-{$info.model_id}&status=1" off="ids={$info.id}-{$info.model_id}&status=0" lay-skin="switch" lay-filter="switchTest" lay-text="显示|隐藏">
											</td>
											<td>
												<div class="layui-inline" style="padding-bottom: 5px;">
													<a class="layui-btn layui-btn-xs " href="javascript:;" onclick="x_admin_show('复制文档','{:url('copy',array('id'=>$info['id'],'model_id'=>$info['model_id']))}','100%','100%',1)">
														<i class="layui-icon layui-icon-edit"></i> 复制
													</a>
												</div>
												<div class="layui-inline" style="padding-bottom: 5px;">
													<a class="layui-btn layui-btn-xs " href="javascript:;" onclick="x_admin_show('编辑文档','{:url('edit',array('id'=>$info['id'],'model_id'=>$info['model_id']))}','100%','100%',1)">
														<i class="layui-icon layui-icon-edit"></i> 编辑
													</a>
												</div>
												<div class="layui-inline" style="padding-bottom: 5px;">
													<a class="layui-btn layui-btn-xs" target="_blank" href="<?php echo get_doc($info['category_id'],$info['id'],'arturl');?>">
														<i class="layui-icon layui-icon-release"></i> 预览
													</a>
												</div>
												<?php if($info['status']==0||$info['status']==2||$info['status']==3):?>
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs layui-btn-normal ajax-get" href="{:url('set_status',array('ids'=>$info['id'].'-'.$info['model_id'],'status'=>1))}">
														<i class="layui-icon layui-icon-release"></i> 显示
													</a>
												</div>
												<?php elseif($info['status']=='1'):?>
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs layui-btn-warm ajax-get" href="{:url('set_status',array('ids'=>$info['id'].'-'.$info['model_id'],'status'=>0))}">
														<i class="layui-icon layui-icon-set-fill"></i> 隐藏
													</a>
												</div>
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs layui-btn-warm ajax-get" href="{:url('set_status',array('ids'=>$info['id'].'-'.$info['model_id'],'status'=>'-1'))}">
														<i class="layui-icon layui-icon-set-fill"></i> 删除
													</a>
												</div>
												<?php elseif($info['status']=='-1'):?>
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs layui-btn-normal ajax-get" href="{:url('set_status',array('ids'=>$info['id'].'-'.$info['model_id'],'status'=>1))}">
														<i class="layui-icon layui-icon-release"></i> 还原
													</a>
												</div>
												<!-- 彻底删除 -->
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs layui-btn-danger confirm ajax-get" url="{:url('del',array('ids'=>$info['id'].'-'.$info['model_id']))}">
														<i class="layui-icon layui-icon-delete"></i> 删除
													</a>
												</div>
												<?php endif;?>
												<div class="layui-inline">
													<a class="layui-btn layui-btn-xs " href="javascript:;" onclick="x_admin_show('移动','{:url('move',array('ids'=>$info['id'].'-'.$info['category_id'],'model_id'=>$model_id))}','50%','50%',1)">
														<i class="layui-icon layui-icon-edit"></i> 移动
													</a>
												</div>
											</td>
										</tr>
										{/volist}
										<tr>
											<td align="left" colspan="10" style="padding-left:0;">
												&nbsp;
												<?php if($category_id):?>
												<div class="layui-inline">
													<a onclick="x_admin_show('新增','{:url('add',['category_id'=>$category_id])}','100%','100%',1)" title="新增" class="layui-btn layui-btn-sm">新增</a>
												</div>
												<?php endif;?>
												<div class="layui-inline">
													<a href="" class="layui-btn layui-btn-sm ajax-post" target-form="sort" url="{:url('set_sort')}" title="排序" >排序</a>
												</div>
												<div class="layui-inline">
													<a href="Javascript:;" class="layui-btn layui-btn-sm move" title="移动" >移动</a>
												</div>
												<div class="layui-inline">
													<a href="" class="layui-btn layui-btn-sm layui-btn-normal ajax-post" target-form="ids" url="{:url('set_status',array('status'=>1))}">显示</a>
												</div>
												<div class="layui-inline">
													<a href="" class="layui-btn layui-btn-sm layui-btn-warm ajax-post" target-form="ids" url="{:url('set_status',array('status'=>0))}">隐藏</a>
												</div>
												<div class="layui-inline">
													<a href="" class="layui-btn layui-btn-sm layui-btn-danger confirm ajax-post" target-form="ids" url="{:url('del')}">删除</a>
												</div>
											</td>
										</tr>
									</tbody>
								</table>
							</form>
							<!-- <div id="page">
								<div class="layui-box layui-laypage layui-laypage-default">
									<div class="pagelistbox">
										<span>共 2 页/31条记录 </span>
										<span class="indexPage">首页 </span>
										<strong>1</strong>
										<a href="#">2</a>
										<a class="nextPage" href="#">下页</a>
										<a class="endPage" href="#">末页</a>
									</div>
								</div>
							</div> -->
							<!-- <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-10"><span class="layui-laypage-prev">共 2 页/31条记录</span><a href="javascript:;" class="layui-laypage-prev" data-page="1">首页</a><a href="javascript:;" class="layui-laypage-prev" data-page="1">上一页</a><a href="javascript:;" data-page="1">1</a><span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>2</em></span><a href="javascript:;" data-page="3">3</a><a href="javascript:;" data-page="4">4</a><a href="javascript:;" data-page="5">5</a><span class="layui-laypage-spr">…</span><a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="10">10</a><a href="javascript:;" class="layui-laypage-next" data-page="3">下一页</a><a href="javascript:;" class="layui-laypage-next" data-page="3">尾页</a><a href="javascript:;" data-page="2" class="layui-laypage-refresh"><i class="layui-icon layui-icon-refresh"></i></a><span class="layui-laypage-skip">到第<input type="text" min="1" value="2" class="layui-input">页<button type="button" class="layui-laypage-btn">确定</button></span></div> -->
							<!-- <div id="page">
								<div class="layui-box layui-laypage layui-laypage-default">
									<div class="pagelistbox">
									</div>
								</div>
							</div> -->
							<div id="page">
								<div class="layui-box layui-laypage layui-laypage-default">
									<div class="pagelistbox">
										<!-- 分页 -->
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="footer"}
{/block}
{block name="js"}
<script type="text/javascript">
	$(function() {
        $("select[name='status']").val({$status|default = ''});
        $("select[name='sort']").val("{$sort|default = ''}");
        $("select[name='flags']").val("{$flags|default = ''}");
        xuanran('select');
    });
</script>
<script type="text/javascript">
	layui.use(['form','table','jquery','laypage','layer','laydate'], function(){
		var form = layui.form
		,table = layui.table
		,laypage = layui.laypage //分页组件
		,layer = layui.layer//弹框组件
		,$ = layui.jquery//jquery
		,laydate = layui.laydate;//日期
		// 执行一个laypage实例(数组分页)
		laypage.render({
		    elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
		    ,count: {$page.count} //数据总数，从服务端得到
		    ,limit: {$page.limit} //每页显示的条数。laypage将会借助 count 和 limit 计算出分页数，从服务端得到
			,limits:[5,10,20,30,40,50,60,70,80,90,100] //每页条数的选择项。如果 layout 参数开启了 limit，则会出现每页条数的select选择框
		    ,curr: {$page.curr} //起始页。一般用于刷新类型的跳页以及HASH跳页，从服务端得到
		    ,groups:5   //连续出现的页码个数
		    ,layout:['count','prev', 'page', 'next','skip','limit','refresh'] //自定义排版。可选值有：count（总条目输区域）、prev（上一页区域）、page（分页区域）、next（下一页区域）、limit（条目选项区域）、refresh（页面刷新区域。注意：layui 2.3.0 新增） 、skip（快捷跳页区域）
		    ,jump: function(obj, first){
			    // obj包含了当前分页的所有参数，比如：
			    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
			    console.log(obj.limit); //得到每页显示的条数
			    // 首次不执行
			    if(!first){
			    	// do something
			    	location.href = "?date={:input('date')}&status={:input('status')}&category_id={:input('category_id')}&sort={:input('sort')}&flags={:input('flags')}&title={:input('title')}"+"&page="+obj.curr+"&limit="+obj.limit;
			  	}
			}
		});
		laydate.render({
			elem: '#laydate',
			range: true,
		});
		$('body').on('click', '.move', function() {
			var arr = [];
	        $("input:checkbox[class='ids']:checked").each(function(i){
		    	// arr.push($(this).val());
		        arr.push($(this).attr('id-cid'));
	        });
			if (arr.length > 0) {
				data=arr.join("|");
				x_admin_show("移动","{:url('move')}?ids="+data+"&model_id={$model_id}","50%","50%",1)
			} else {
				layer.msg("请选择需要移动的数据",{icon: 2,time:2000});
			}
		});
	});
</script>
{/block}